<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        class Queue {
            constructor(items) {
                this.items = items
            }
            //将元素加入到队列中
            enqueue(element) {
                this.items.push(element)
            }
            //删除队列前端元素
            dequeue() {
                return  this.items.shift()
            }
            //查看前端的元素
            front() {
                return  this.items[0]
            }
            //查看队列是否为空
            isEmpty() {
                return  this.items.length > 0 ? false : true
            }
            //查看队列中元素的个数
            size() {
                return  this.items.length;
            }
            //toString方法
            toString() {
                let resultString = ''
                for (let i of  this.items) {
                    resultString += i + ' '
                }
                return resultString
            }
        }

       function drummingToPassFlowers(nameList, num) {
          var items=[];
            let queue = new Queue(items);
            for (const name of nameList) {
                queue.enqueue(name)
            }
         
            while (queue.size() > 1) {
                for (let index = 0; index < num - 1; index++) {
           
                    queue.enqueue(queue.dequeue())
                }
                queue.dequeue();
            }
            return queue.toString()
        }
        const nameList = ['Lily', 'Lucy', 'Tom', 'LiLei', 'why']
        
        console.log(drummingToPassFlowers(nameList, 3)); 
    </script>
</body>

</html>